'''
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with self work for additional information
 * regarding copyright ownership.  The ASF licenses self file
 * to you under the Apache License, Version 2.0 (the
 * "License") you may not use self file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *     http:#www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
'''
from base.graph.Node_Concrete import Node_Concrete

#import org.apache.jena.datatypes.RDFDatatype;
#import org.apache.jena.graph.impl.*;
#import org.apache.jena.shared.*;

'''
 * An RDF node holding a literal value. Literals may have datatypes.
'''
class Node_Literal(Node_Concrete):
    # ''' package''' Node_Literal(LiteralLabel label):
    #     super().__init__(label)
    def __init__(self, label):
        super().__init__(label)

    #@Override
    # param 
    # result LiteralLabel
    def getLiteral(self):
        return self.label
    

    #@Override
    # param 
    # result final Object
    def getLiteralValue(self):
        return self.getLiteral().getValue()
    

    #@Override
    # param 
    # result final String
    def getLiteralLexicalForm(self):
        return self.getLiteral().getLexicalForm()
    

    #@Override
    # param 
    # result final String
    def getLiteralLanguage(self):
        return self.getLiteral().language()
    

    #@Override
    # param 
    # result final String
    def getLiteralDatatypeURI(self):
        return self.getLiteral().getDatatypeURI()
    

    #@Override
    # param 
    # result final RDFDatatype
    def getLiteralDatatype(self):
        return self.getLiteral().getDatatype()
    

    #@Override
    # param 
    # result final boolean
    def getLiteralIsXML(self):
        return self.getLiteral().isXML()
    

    #@Override
    # param PrefixMapping pm, boolean quoting
    # result String
    def toString(self, pm, quoting):
        #return ((LiteralLabel) label).toString2(quoting)
        return self.label.toString2(quoting)
    

    #@Override
    # param 
    # result boolean
    def isLiteral(self):
        return True
    

    '''
     * Literal nodes defer their indexing value to the component literal.
     *
     * @see org.apache.jena.graph.Node#getIndexingValue()
    '''
    #@Override
    # param 
    # result Object
    def getIndexingValue(self):
        return self.getLiteral().getIndexingValue()
    

    #@Override
    # param NodeVisitor v
    # result Object
    def visitWith(self, v):
        return v.visitLiteral(self, self.getLiteral())
    

    #@Override
    # param Object other
    # result boolean
    def equals(self, other):
        if (self == other):
            return True
        #return other instanceof Node_Literal and label.equals(((Node_Literal) other).label)
        return isinstance(other, Node_Literal) and self.label.equals(other.label)
    

    '''
     * Test that two nodes are semantically equivalent.
     * In some cases self may be the same as equals, in others
     * equals is stricter. For example, two xsd:int literals with
     * the same value but different language tag are semantically
     * equivalent but distinguished by the java equality function
     * in order to support round tripping.
     * <p>Default implementation is to use equals, subclasses should
     * override self.</p>
    '''
    #@Override
    # param Object o
    # result boolean
    def sameValueAs(self, o):
        #return o instanceof Node_Literal and ((LiteralLabel) label).sameValueAs(((Node_Literal) o).getLiteral())
        return isinstance(o, Node_Literal) and self.label.sameValueAs(o.getLiteral())


    #@Override
    # param Node x
    # result boolean
    def matches(self, x):
        return self.sameValueAs(x)
    


